﻿package mortal.game.view.guild.otherpanel
{
    import Message.Game.*;
    import Message.Public.*;
    import com.mui.controls.*;
    import extend.language.*;
    import flash.events.*;
    import mortal.game.events.*;
    import mortal.game.manager.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.resource.info.item.*;
    import mortal.game.utils.*;
    import mortal.game.view.common.*;
    import mortal.game.view.common.item.*;
    import mortal.game.view.common.menu.*;
    import mortal.mvc.core.*;
    import mortal.mvc.interfaces.*;

    public class GuildWareHouseApplyItem extends GuildOtherBasePanel
    {
        private var _item:BaseItem;
        private var _itemName:GTextFiled;
        private var _txtOprType:GTextFiled;
        private var _numInput:GNumericStepper;
        private var _btnYes:GButton;
        private var _btnNo:GButton;
        private var _itemData:ItemData;
        private var _operate:String;
        private var _uiCreateCom:Boolean = false;
        private static var _instance:GuildWareHouseApplyItem;

        public function GuildWareHouseApplyItem(param1:ILayer = null)
        {
            setSize(245, 150);
            super(param1);
            layer = LayerManager.topLayer;
            if (_instance)
            {
                throw new Error("单例");
            }
            return;
        }// end function

        override public function layoutUI() : void
        {
            super.layoutUI();
            this._item = UIFactory.getUICompoment(BaseItem, 25, 48, this);
            this._item.setItemStyle(ItemStyleConst.Small, ImagesConst.PackItemBg, 2, 3);
            this._itemName = UIFactory.textField("", 70, 48, 100, 22, this);
            this._txtOprType = UIFactory.textField("" + Language.getString(71230), 70, 68, 100, 22, this);
            this._numInput = UIFactory.gNumericStepper(128, 66, 49, 20, this, 999, 1, "NumericStepper");
            this._numInput.configEventListener(Event.CHANGE, this.onUpdateNumInput);
            this._btnYes = UIFactory.gButton("" + Language.getString(71231), 46, 110, 65, 22, this);
            this._btnNo = UIFactory.gButton("" + Language.getString(71232), 135, 110, 65, 22, this);
            this._uiCreateCom = true;
            return;
        }// end function

        private function onUpdateNumInput(event:Event) : void
        {
            return;
        }// end function

        override public function onMouseClick(event:MouseEvent) : void
        {
            var _loc_2:Object = null;
            var _loc_3:SPlayerItem = null;
            super.onMouseClick(event);
            switch(event.target)
            {
                case this._btnYes:
                {
                    _loc_2 = {};
                    if (this._operate == ItemMenuConst.APPLY)
                    {
                        _loc_2.uid = this._itemData.uid;
                        _loc_2.amount = this._numInput.value;
                        _loc_2.donateMoney = null;
                        Dispatcher.dispatchEvent(new DataEvent(EventName.Guild_wareHouse_applyRequst, _loc_2));
                    }
                    else if (this._operate == ItemMenuConst.EXTRACTION)
                    {
                        _loc_3 = new SPlayerItem();
                        _loc_3.uid = this._itemData.serverData.uid;
                        _loc_3.itemCode = this._itemData.serverData.itemCode;
                        _loc_3.itemAmount = this._numInput.value;
                        _loc_2.oper = new EGuildWarehouseOper(EGuildWarehouseOper._EGuildWarehouseOut);
                        _loc_2.item = [_loc_3];
                        _loc_2.oprMoney = null;
                        Dispatcher.dispatchEvent(new DataEvent(EventName.Guild_wareHouse_oper, _loc_2));
                    }
                    this.hide();
                    break;
                }
                case this._btnNo:
                {
                    this.hide();
                    break;
                }
                default:
                {
                    break;
                }
            }
            return;
        }// end function

        override public function update() : void
        {
            super.update();
            if (this._itemData == null || !this._uiCreateCom)
            {
                return;
            }
            title = this._operate + "" + Language.getString(71233);
            this._item.itemData = this._itemData;
            this._itemName.htmlText = ItemsUtil.getItemName(this._itemData);
            this._txtOprType.text = this._operate + "" + Language.getString(71234);
            this._numInput.minimum = 1;
            this._numInput.maximum = this._itemData.itemAmount;
            this._numInput.visible = this._itemData.itemInfo.overlay > 1;
            return;
        }// end function

        public function showPanel(param1:ItemData, param2:String) : void
        {
            this._itemData = param1;
            this._operate = param2;
            this.show();
            this.update();
            return;
        }// end function

        override public function hide() : void
        {
            this._itemData = null;
            this._operate = "";
            super.hide();
            return;
        }// end function

        public static function get instance() : GuildWareHouseApplyItem
        {
            if (_instance == null)
            {
                _instance = new GuildWareHouseApplyItem;
            }
            return _instance;
        }// end function

    }
}
